FROM golang:1.18.3-alpine As builder

ENV GO111MODULE=on

ENV GOPROXY=https://goproxy.cn/

WORKDIR /app

## 进入项目文件夹
COPY go.mod .
COPY go.sum .
## 下载包
RUN go mod download
# 项目复制到容器里
ADD . /app
# 编译go项目
RUN go build -o ./buildMaster master/main/master.go
# docker镜像分层构建 可以区分编译环境和运行环境
FROM alpine:3.16.0

WORKDIR /app

COPY --from=builder /app/buildMaster/master .
COPY --from=builder /app/master/webroot ./webroot
COPY --from=builder /app/master/master.json .

## 启动go项目
CMD ["sh","-c","/app/master -config ./master.json"]
